<?php
namespace app\wxapp\controller;

use app\model\Record; 
use app\model\Theme; 
use app\model\Worker; 
use app\model\Order; 

class Mypay extends Base
{
    public function Mypay()
    {

    global $_P, $_G;
    $system=$_G['system'];
    $fans = $this->checkuser();
    $themeid = intval($_P['themeid']);
    $theme = Theme::getThemeByIdxcx($themeid);
    if(empty($theme['id'])){
        $this->result(1, '活动入口不正确'); 
        exit;
    }
    $config =   Theme::getConfig($themeid);
    

    //未支付的进行较验是否已支付
    Order::checkorder($themeid,$config,$system);

    $themyrecord = Record::getLastGroupByOpenId($fans['openid'],$themeid);
    if(!empty($themyrecord)){
        if ($themyrecord['type']==1){
            $recordid = $themyrecord['pid'];
        }else{
            $recordid = $themyrecord['id'];
            $isleader = 1;
        }
        $themyrecordid = $recordid+1000;
    }else{
        $this->result(1, '未查到您的付款定单'); 
        exit;
    }
    if ($themyrecord['status']==3) {
        $themyorder['uniontid']="线下支付定单";
        $themyorder['realfee']=$themyrecord['fee'];
    }else{
        $themyorder = Order::getPayOrderByRIdZhifude($themyrecord['id']);
    }
    $themyrecord['mobile']=mb_substr($themyrecord['mobile'],0,3,'utf-8').'****'.mb_substr($themyrecord['mobile'],$usernamelen-4,4,'utf-8');

    $worker=db_find("SELECT * FROM ".tablename(t_worker)." WHERE uid = '{$themyrecord['workerid']}'");

    $shareinfo =Theme::getshareinfo($theme,$config,$fans,$shopname,$workername,$recordid);

    $themyorder['realfee']=sprintf("%.2f",$themyorder['realfee']);
    $theme['jubf']=empty($theme['jubf'])?mb_substr($theme['title'],0,12,'utf-8'):$theme['jubf'];

    $confignnew =  array();
    $confignnew['zhuandantxt'] = $confign['zhuandantxt'];
    $confignnew['zhuandantips'] = $confign['zhuandantips'];
    $confignnew['addresstxt'] = $config['province'].$config['city'].$config['district'].$config['addresstxt'];
    $confignnew['zhuandanbegintime']=date('Y-m-d',$config['zhuandanbegintime']);
    $confignnew['zhuandanendtime']=date('Y-m-d',$config['zhuandanendtime']);
    if (intval($_P['showimg'])==1 && !empty($config['zhuandanimg'])) {
        $zhuandanimg = $config['zhuandanimg'];
    }else{
        $zhuandanimg = "";
    }
    $result =  array();
    $result['jishu']=Worker::getjishu($theme,$system);
    $result['themyorder']=$themyorder;
    $result['themyrecord']=$themyrecord;
    $result['worker']=$worker;
    $result['config']=$confignnew;
    $result['shareinfo']=$shareinfo;
    $result['zhuandanimg']=$zhuandanimg;
    $result['fans']=$fans;
    $result['theme']=$theme;
    $this->result(0, '成功', $result); 
}
}